﻿using System;
using SDCloudSolution.SDCloud.Web.Infrastructure.Interfaces;

namespace SDCloudSolution.SDCloud.Web.Infrastructure
{
    public class DateTimeFormatter : IDateTimeFormatter
    {
        public string ToFullDateTimeFormat(DateTime dateTime)
        {
            return dateTime.ToString("dd MMM yyyy HH:mm:ss");
        }

        public string ToFullDateFormat(DateTime dateTime)
        {
            return dateTime.ToString("dd MMM yyy");
        }

        public string ToUserFriendlyDateFormat(DateTime dateTime)
        {
            // TODO Implement this method
            return ToFullDateTimeFormat(dateTime);
        }

        public string ToTimeFormat(TimeSpan timeSpan)
        {
            if (timeSpan.TotalDays < 1)
            {
                return timeSpan.ToString(@"hh\:mm\:ss");
            }

            return string.Format("{0} {1} {2}", 
                (int)Math.Floor(timeSpan.TotalDays), 
                timeSpan.TotalDays < 2
                    ? "day"
                    : "days",
                timeSpan.ToString(@"hh\:mm\:ss"));
        }

        public string ToUserFriendlyTimeFormat(TimeSpan timeSpan)
        {
            // TODO Implement this method
            return ToTimeFormat(timeSpan);
        }
    }
}